/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fjnu.dao.mysql;

import fjnu.dao.factory.AbstractConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author neco
 */
class MysqlConnection extends AbstractConnection {

    private final static String DRIVER = "com.mysql.jdbc.Driver";
    private final static String URL = "jdbc:MySQL://192.168.1.104:3306/fjnu";
    private final static String USER = "root";
    private final static String PASSWD = "root";
    
   // private final static String URL = "jdbc:MySQL://localhost:3306/fjnu";
   // private final static String USER = "root";
   // private final static String PASSWD = "zhanglei";
    
    private int refCount=0;
    private Connection conn;
    
    public int getRefCount()
    {
        return refCount;
    }

    public void updateRefCount()
    {
        refCount++;
    }
    public void loadDriver() {
       
        try {
            Class.forName(DRIVER);
            conn = DriverManager.getConnection(URL, USER, PASSWD);
            if (!conn.isClosed()) {

            }
        } catch (ClassNotFoundException ex) {
            System.err.println("Sorry,can`t find the Driver!");
            Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
      
    }

     boolean isClosed() throws SQLException
     {
         if(conn!=null)
         return conn.isClosed();
         else 
             return true;
     }
   
    
     void cloesConn() {
        try {
            if (!conn.isClosed()) {
                conn.close();
            }
            if (conn == null) {
            }
        } catch (SQLException ex) {
            Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
     }
     
     Statement creatStatment()
     {
         Statement stm=null;
        try {
            stm= conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
        }   
        return stm;
     }
}
